package com.yc.baihe.utils;

public class PageUtil {
	private int pageSize=5;//每页显示几条
	private int pageNo=1;//当前页
	private int totalPage=1;//总页数
	private int totalSize;//总记录数
	
	@Override
	public String toString() {
		return "PageUtil [pageSize=" + pageSize + ", pageNo=" + pageNo
				+ ", totalPage=" + totalPage + ", totalSize=" + totalSize + "]";
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		if(pageSize<=0){//如果给定的每页显示的条数不合法，则默认为5条
			this.pageSize=5;
		}else{
			this.pageSize = pageSize;
		}
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		if(pageNo<1){//如果已经是第一页了，则不再往下
			pageNo=1;
		}else if(pageNo>totalPage){//如果已经是最后一页了，则不再往上
			pageNo=totalPage;
		}else{
			this.pageNo = pageNo;
		}
	}

	public int getTotalSize() {
		return totalSize;
	}

	public void setTotalSize(int totalSize) {
		this.totalSize = totalSize;
	}

	public int getTotalPage() {
		totalPage=this.totalSize%this.pageSize==0?this.totalSize/this.pageSize:this.totalSize/this.pageSize+1;
		return totalPage;
	}

	public PageUtil(int pageSize, int pageNo, int totalPage, int totalSize) {
		super();
		this.pageSize = pageSize;
		this.pageNo = pageNo;
		this.totalPage = totalPage;
		this.totalSize = totalSize;
	}

	public PageUtil() {
		super();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + pageNo;
		result = prime * result + pageSize;
		result = prime * result + totalPage;
		result = prime * result + totalSize;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PageUtil other = (PageUtil) obj;
		if (pageNo != other.pageNo)
			return false;
		if (pageSize != other.pageSize)
			return false;
		if (totalPage != other.totalPage)
			return false;
		if (totalSize != other.totalSize)
			return false;
		return true;
	}
}
